home *** CD-ROM | disk | FTP | other *** search
/ Do It! 2 / Do It! Volume 2.iso / for_amiga / diavolodemo / db302dem.lha / Misc / API / DiavoloAPITest / DiavoloAPITest.c next >
C/C++ Source or Header  |  1995-10-11  |  30KB  |  834 lines

  1. /* Diavolo API Test */
  2.  
  3. /*
  4.  
  5.     This file is meant as an example for programming the Diavolo Application Programming
  6.     Interface.
  7.  
  8.     It contains a frame of routines which you can use in your own application.
  9.  
  10.     You will also find a sequence of commands send to Diavolo (in main()) which I used
  11.     to test the API. Use them as an example how they work. They will most likely NOT
  12.     work on your system as I used names and paths only valid on my machine. But if
  13.     you want to test a specific command, just comment out the not needed commands and
  14.     correct the parameters as needed on your system. Then you can compile this source
  15.     and start the resulting program.
  16.  
  17.     This source was written and tested using SAS/C 6.51.
  18.     Nested comments and C++-style comments must be enabled to compile the file correctly.
  19.  
  20.     For a detailed documentation of the API see DiavoloAPI.h and DiavoloPrefs.h.
  21.  
  22.  
  23.     If you want to print this file, set your printer to 136 characters per line (condensed font).
  24.  
  25.  
  26.     © 1995 Martin Korndörfer.
  27.  
  28. */
  29.  
  30. /* *********************************************************************** */
  31. /* *********************************************************************** */
  32. /*                                                                         */
  33. /* Includes                                                                */
  34. /*                                                                         */
  35. /* *********************************************************************** */
  36. /* *********************************************************************** */
  37.  
  38.  
  39. #include <clib/locale_protos.h>             /* Contains all prototypes for Amiga functions. May
  40.                                                have a different name when using another compiler */
  41.  
  42.  
  43. #include <dos/dos.h>
  44. #include <exec/exec.h>
  45. #include <stdio.h>
  46. #include <string.h>
  47.  
  48. #include "sas:Diavolo/DiavoloPrefs.h"       /* Contains documented preference structure and constants */
  49. #include "sas:Diavolo/DiavoloAPI.h"         /* Structures, constants and documentation of Diavolo API */
  50.  
  51.  
  52.  
  53. /* *********************************************************************** */
  54. /* *********************************************************************** */
  55. /*                                                                         */
  56. /* Global variables                                                        */
  57. /*                                                                         */
  58. /* *********************************************************************** */
  59. /* *********************************************************************** */
  60.  
  61. struct      MsgPort         *MyReplyPort;   /* Global Reply Port. Will be used by Diavolo to send its
  62.                                                messages to the client */
  63.  
  64. struct      MsgPort         *APIPort;       /* API Port of Diavolo Backup. Global message port which
  65.                                                must be used to send messages to Diavolo */
  66.  
  67. BOOL                        Quit;           /* TRUE: Quit requested by Diavolo */
  68.  
  69.  
  70. /* *********************************************************************** */
  71. /* *********************************************************************** */
  72. /*                                                                         */
  73. /* Forward function declarations                                           */
  74. /*                                                                         */
  75. /* *********************************************************************** */
  76. /* *********************************************************************** */
  77.  
  78.  
  79. void    CheckDAPIMsg(struct DiavoloAPIMsg   *APIMsg);
  80.  
  81.  
  82. /* *********************************************************************** */
  83. /* *********************************************************************** */
  84. /*                                                                         */
  85. /* Frame functions, use them in your code                                  */
  86. /*                                                                         */
  87. /* *********************************************************************** */
  88. /* *********************************************************************** */
  89.  
  90. void    CheckRequest(struct    DiavoloAPIMsg   *APIMsg)
  91.  
  92. /* Will be used to process incoming request messages. After a client has made contact with
  93.    Diavolo, before a requester is displayed to the user, a message will be sent to the client.
  94.    The client can answer this request itself, so the user never sees the request, or make Diavolo
  95.    display the request as normal. Anyway, the client MUST reply the request as fast as possible,
  96.    so the message port must be always watched for incoming messages. If the client does not reply
  97.    a message, there could be a deadlock (Diavolo waiting for client and client waiting for
  98.    Diavolo).
  99.  
  100.    Modify this routine to customize the clients reaction to requesters. Look at the DAPI_RC_...
  101.    defines at the end of DiavoloAPI.h for all possible request codes and their meaning.
  102.  
  103. */
  104.  
  105. {
  106.     ULONG                       RetVal;
  107.  
  108.  
  109.     /* At first the client displays the requester text. This is just for testing and
  110.        should not be used in a final client application - at least not THIS way. */
  111.  
  112.     printf("Title: %s\n",APIMsg->DAPI_Ptr1);
  113.     printf("Body:\n%s\n",APIMsg->DAPI_Ptr2);
  114.     printf("Gadgets: %s\n",APIMsg->DAPI_Ptr3);
  115.     printf("Code: %ld\n",APIMsg->DAPI_Arg1);
  116.  
  117.  
  118.     /* This switch/case statement decides what to do with the requester. */
  119.  
  120.     switch(APIMsg->DAPI_Arg1)
  121.     {
  122.         /* The following requests shall not be displayed to the user. Instead Diavolo should
  123.            react as if the user presses RETRY. */
  124.  
  125.         case DAPI_RC_INSERTDISK:        /* Insert disk in any drive... */
  126.         case DAPI_RC_INSERTDIRDISK:     /* Insert first disk in any drive. */
  127.         case DAPI_RC_BACKDISK:          /* This disk contains another backup... */
  128.         case DAPI_RC_DOSDISK:           /* This disk is DOS formatted ... */
  129.         case DAPI_RC_ALIENTAPE:         /* This tape contains unreadable data or is empty ... */
  130.  
  131.             RetVal = 1;                 /* RetVal will be used as a replycode to Diavolo.
  132.                                            1 means the leftmost option, RETRY in these cases. */
  133.             break;
  134.  
  135.         default:                        /* In all other cases... */
  136.  
  137.             RetVal = ~0;                /* A RetVal of ~0 (bitwise NOT 0, in other words all bits set)
  138.                                            means that Diavolo should display the requester as normal */
  139.     }
  140.  
  141.     APIMsg->DAPI_Arg1 = RetVal;         /* Return the message with RetVal set in Arg1 */
  142.     ReplyMsg(APIMsg);
  143. }
  144.  
  145.  
  146.  
  147.  
  148. void    CheckDAPIMsg(struct DiavoloAPIMsg   *APIMsg)
  149.  
  150. /* Check incoming messages. */
  151.  
  152. {
  153.     if(APIMsg->DAPI_Message.mn_Node.ln_Type == NT_REPLYMSG)
  154.     /* The received message was a reply. Normally replies will only be received after you've sended
  155.        a message to Diavolo in the first place. This example is written in a way that every
  156.        routine knows its sent messages and handles its replies itself, so this generic routine
  157.        should never has to handle replies. */
  158.     {
  159.         printf("Reply received. Don't know original message. ERROR!\n");
  160.     }
  161.  
  162.     else
  163.     {
  164.         /* What kind of message is this? */
  165.  
  166.         switch(APIMsg->DAPI_Command)
  167.         {
  168.             case    DAPI_REQUEST:
  169.                 /* Diavolo has a request. CheckRequest (see above) handles them */
  170.                 CheckRequest(APIMsg);
  171.                 break;
  172.  
  173.             case    DAPI_CLOSEDOWN:
  174.                 /* Diavolo is closing down. The client is informed that it has to cut down
  175.                    the link to Diavolo, so it can complete the closedown. */
  176.  
  177.                 Quit = TRUE;            /* Set global Quit flag to TRUE */
  178.                 ReplyMsg(APIMsg);       /* Return message */
  179.                 break;
  180.  
  181.             default:
  182.                 /* Another - unknown - message has arrived. Diavolo only sends the two
  183.                    messages handled above or replies. */
  184.  
  185.                 printf("Unknown message. Command: %lx\n",APIMsg->DAPI_Command);
  186.                 ReplyMsg(APIMsg);
  187.                 break;
  188.         }
  189.     }
  190. }
  191.  
  192.  
  193.  
  194. BOOL    DoCommand(struct DiavoloAPIMsg *APIMsg)
  195.  
  196. /* Send a command to Diavolo and wait for its completion (its reply).
  197.  
  198.    This routine handles all incoming message (also requests) and waits until the command
  199.    was replied.
  200.  
  201.    Use this for all commands you want to send synchronously (which should be most). You
  202.    cannot use them for asynchronous command, which are used to initiate an operation.
  203.    These are DAPI_STARTBACKUP, DAPI_STARTSCAN and DAPI_STARTRESTORE. Use seperate
  204.    routines for these commands (see below).
  205.  
  206.    The parameter APIMsg must be filled with the correct parameters you want to send to
  207.    Diavolo (also the command code itself). After the routine replies you can find the
  208.    result codes set by Diavolo in the same structure.
  209. */
  210.  
  211. {
  212.     struct  DiavoloAPIMsg       *Reply;
  213.     BOOL                        Ok;
  214.  
  215.     /* Set Replyport of the message to send to the global client message port */
  216.     APIMsg->DAPI_Message.mn_ReplyPort = MyReplyPort;
  217.  
  218.     /* Send the message to Diavolo's API Port */
  219.     PutMsg(APIPort, APIMsg);
  220.  
  221.     do
  222.     {
  223.         /* This is a generic method of waiting for a message. If you want to check more
  224.            than one message port, you'll have to add more bits to the Wait() mask. */
  225.  
  226.         while(! (Reply = (struct DiavoloAPIMsg *)GetMsg(MyReplyPort)))
  227.             Wait(1l << MyReplyPort->mp_SigBit);
  228.  
  229.  
  230.         if(Reply->DAPI_Message.mn_Node.ln_Type != NT_REPLYMSG || Reply != APIMsg)
  231.         {
  232.             /* The received message wasn't the reply for our own message, so process it */
  233.  
  234.             CheckDAPIMsg(Reply);
  235.             Reply = NULL;           /* No, we're not finished yet */
  236.         }
  237.         else
  238.         {
  239.             /* Our message has been replied. Fine, now look if there was an error
  240.                set in the reply: */
  241.  
  242.             switch(Reply->DAPI_Errorcode)
  243.             {
  244.                 case DAPI_EC_NOERROR:
  245.                     /* Everything was fine! */
  246.  
  247.                     printf("Reply: No error!\n");
  248.                     Ok = TRUE;
  249.                     break;
  250.  
  251.                 case DAPI_EC_INUSE:
  252.                     /* Diavolo's messageport is in use by another application */
  253.  
  254.                     printf("Reply: In Use error\n");
  255.                     Ok = FALSE;
  256.                     break;
  257.  
  258.                 case DAPI_EC_NOTAVAILABLE:
  259.                     /* The sent command is not available at this moment or entirely unknown */
  260.  
  261.                     printf("Reply: Command not available!\n");
  262.                     Ok = FALSE;
  263.                     break;
  264.  
  265.                 case DAPI_EC_NOTMETYET:
  266.                     /* You have not intiated the dialogue using DAPI_RENDEZVOUS yet */
  267.  
  268.                     printf("Reply: Programs not met yet!\n");
  269.                     Ok = FALSE;
  270.                     break;
  271.  
  272.                 case DAPI_EC_INVALIDCONFIG:
  273.                     /* The new configuration was invalid */
  274.  
  275.                     printf("Reply: Invalid config!\n");
  276.                     Ok = FALSE;
  277.                     break;
  278.  
  279.                 case DAPI_EC_SELECTFAILED:
  280.                     /* The selection (in DAPI_BACKSELECT and DAPI_RESTSELECT) failed */
  281.  
  282.                     printf("Reply: Selection failed. Code: %ld!\n", Reply->DAPI_Arg1);
  283.                     Ok = FALSE;
  284.                     break;
  285.  
  286.                 case DAPI_EC_OPPENDING:
  287.                     /* You cannot cut the connection (using DAPI_GOODBYE) while a client
  288.                        intiated operation is in progress. Cancel the operation first! */
  289.  
  290.                     printf("Reply: Operation pending, Goodbye not possible!\n");
  291.                     Ok = FALSE;
  292.                     break;
  293.  
  294.                 case DAPI_EC_OPFAILED:
  295.                     /* The oepration failed */
  296.  
  297.                     printf("Reply: Operation failed, Code: %ld!\n",Reply->DAPI_Arg1);
  298.                     Ok = FALSE;
  299.                     break;
  300.  
  301.                 default:
  302.                     printf("Unknown errorcode: %ld\n",Reply->DAPI_Errorcode);
  303.                     Ok = FALSE;
  304.             }
  305.         }
  306.     }
  307.     while(Reply == NULL);
  308.     return(Ok);
  309. }
  310.  
  311.  
  312.  
  313. void    WaitForCompletion(struct DiavoloAPIMsg *OpMsg)
  314.  
  315. /* This routine can be used by any asynchronous request to wait for its completion.
  316.  
  317.    In this program, it's used by DoBackup(), DoScan() and DoRestore(). It's not
  318.    very smart, but it shows an example how to use DAPI_INQUIRY while the operation
  319.    is in progress, to get a status report of the operation.
  320.  
  321.    In a real application you shouldn't use Delay() of course!
  322.  
  323.    The parameter is the message sent to intitiate the operation (and this routine is
  324.    supposed to wait for).
  325. */
  326.  
  327. {
  328.     struct      DiavoloAPIMsg       APIMsg, *RepMsg;
  329.     int                             z1;
  330.     BOOL                            Ende;
  331.     struct      DiavoloInquiry      DI;
  332.  
  333.     z1 = 0;
  334.     do
  335.     {
  336.         /* Wait for a short moment, to avoid 100% cpu usage
  337.  
  338.            THIS IS BAD STYLE!
  339.  
  340.            It's only a simple example, to show how DAPI_INQUIRY can be used while the
  341.            client is waiting for the reply.
  342.  
  343.            A real application would use timer.device events instead */
  344.         Delay(10);
  345.  
  346.  
  347.         Ende = FALSE;
  348.  
  349.         while(RepMsg = (struct DiavoloAPIMsg *)GetMsg(OpMsg->DAPI_Message.mn_ReplyPort))
  350.         {
  351.             if(RepMsg == OpMsg)
  352.             {
  353.                 /* The operation command was replied. The operation has been finished, either
  354.                    because it was completed or aborted */
  355.  
  356.                 printf("Backup complete! Errorcode: %ld, Arg1: %ld, Arg2: %ld, Arg3: %ld\n",RepMsg->DAPI_Errorcode,
  357.                         RepMsg->DAPI_Arg1, RepMsg->DAPI_Arg2, RepMsg->DAPI_Arg3);
  358.                 Ende = TRUE;
  359.             }
  360.         }
  361.  
  362.         if(z1 == 25)
  363.         {
  364.             /* Every 25th loop iteration, send DAPI_INQUIRY */
  365.  
  366.             z1 = 0;     /* Reset loop counter */
  367.  
  368.             /* Send DAPI_INQUIRY. Arg1 has to be set to the size of your buffer and Ptr1 must point
  369.                to the beginning of your buffer */
  370.  
  371.             APIMsg.DAPI_Command = DAPI_INQUIRY;
  372.             APIMsg.DAPI_Arg1 = sizeof(struct DiavoloInquiry);
  373.             APIMsg.DAPI_Ptr1 = &DI;
  374.             DoCommand(&APIMsg);
  375.  
  376.  
  377.             /* Show some of the values returned by DAPI_INQUIRY in the CLI */
  378.  
  379.             printf("Status: %ld, Medium: %ld\n",DI.DAPI_ActualStatus, DI.DAPI_BackupMedium);
  380.             printf("Name: %s, ID: %lx, Size: %ld, Files: %ld, Dirs: %ld, Volumes: %ld\n",DI.DAPI_BackName,DI.DAPI_ID,
  381.                    DI.DAPI_BackSize,DI.DAPI_BackFiles,DI.DAPI_BackDirs,DI.DAPI_BackVolumes);
  382.             printf("Current Dir: %s, Current File: %s\n",DI.DAPI_File, DI.DAPI_Dir);
  383.             printf("ActFile: %ld, ActDir: %ld, ActByte: %ld Written: %ld\n",DI.DAPI_FileCount,DI.DAPI_DirCount,DI.DAPI_ByteCount,DI.DAPI_Written);
  384.             printf("Unpacked: %ld, Packed: %ld\n",DI.DAPI_Unpacked, DI.DAPI_Packed);
  385.             printf("DiskStatus: 1: %d, 2: %d, 3: %d, 4: %d\n",DI.DAPI_DiskStatus[0],DI.DAPI_DiskStatus[1],DI.DAPI_DiskStatus[2],DI.DAPI_DiskStatus[3]);
  386.             printf("DiskTrack: 1: %d, 2: %d, 3: %d, 4: %d\n",DI.DAPI_DiskTrack[0],DI.DAPI_DiskTrack[1],DI.DAPI_DiskTrack[2],DI.DAPI_DiskTrack[3]);
  387.             printf("DiskSize: 1: %d, 2: %d, 3: %d, 4: %d\n",DI.DAPI_DiskSize[0],DI.DAPI_DiskSize[1],DI.DAPI_DiskSize[2],DI.DAPI_DiskSize[3]);
  388.             printf("DisksDone: %ld\n",DI.DAPI_DisksDone);
  389.         }
  390.         else
  391.         {
  392.             z1++;       /* Increment loop counter */
  393.  
  394.  
  395.             /* Check the global client message port for messages sent by Diavolo. */
  396.  
  397.             if(RepMsg = (struct DiavoloAPIMsg *)GetMsg(MyReplyPort))
  398.                 CheckDAPIMsg(RepMsg);
  399.         }
  400.     }
  401.     while(! Ende);
  402. }
  403.  
  404.  
  405. void    DoBackup(void)
  406.  
  407. /* This routine starts a backup procedure asynchronously. */
  408.  
  409. {
  410.     struct      DiavoloAPIMsg   APIMsg, BackupMsg;
  411.     struct      MsgPort         *BackReplyPort;
  412.  
  413.     /* To make things easier, I create my own message port to receive the reply of the
  414.        backup command */
  415.  
  416.     if(! (BackReplyPort = CreateMsgPort()))
  417.     {
  418.         printf("Error creating own message port!\n");
  419.         return;
  420.     }
  421.  
  422.     BackupMsg.DAPI_Message.mn_ReplyPort = BackReplyPort;
  423.     BackupMsg.DAPI_Command = DAPI_STARTBACKUP;
  424.     BackupMsg.DAPI_Arg1 = TRUE;       /* Use PW */
  425.     BackupMsg.DAPI_Arg2 = FALSE;      /* Encode data */
  426.     BackupMsg.DAPI_Arg3 = 0;          /* Ask user */
  427.  
  428.     BackupMsg.DAPI_Ptr1 = "Automatische Sicherung von API Test";
  429.     BackupMsg.DAPI_Ptr2 = "Passwort";
  430.  
  431.     printf("Starting backup\n");
  432.     PutMsg(APIPort,&BackupMsg);
  433.  
  434.  
  435.     /* After the backup has been started, unlock the UserInterface. Since the
  436.        backup procedure is asynchronous, we can do that AFTER the backup has
  437.        been started, otherwise it would have to be done before starting it. */
  438.  
  439.     printf("Unlocking UI\n");
  440.     APIMsg.DAPI_Command = DAPI_LOCKUI;
  441.     APIMsg.DAPI_Arg1 = FALSE;
  442.     DoCommand(&APIMsg);
  443.  
  444.     WaitForCompletion(&BackupMsg);
  445.  
  446.     DeleteMsgPort(BackReplyPort);
  447. }
  448.  
  449. void    DoRestore(ULONG Command)
  450.  
  451. /* This routine starts a restore procedure asynchronously. See DoBackup() for
  452.    details. The parameter Command contains the command code actually sent
  453.    to Diavolo, so this routine can be used for restore AND compare operations. */
  454.  
  455. {
  456.     struct      DiavoloAPIMsg   APIMsg, RestoreMsg;
  457.     struct      MsgPort         *RestReplyPort;
  458.  
  459.     if(! (RestReplyPort = CreateMsgPort()))
  460.     {
  461.         printf("Error creating own message port!\n");
  462.         return;
  463.     }
  464.  
  465.     RestoreMsg.DAPI_Message.mn_ReplyPort = RestReplyPort;
  466.     RestoreMsg.DAPI_Command = Command;
  467.  
  468.     printf("Starting Restore\n");
  469.     PutMsg(APIPort,&RestoreMsg);
  470.  
  471.     printf("Unlocking UI\n");
  472.     APIMsg.DAPI_Command = DAPI_LOCKUI;
  473.     APIMsg.DAPI_Arg1 = FALSE;
  474.     DoCommand(&APIMsg);
  475.  
  476.     WaitForCompletion(&RestoreMsg);
  477.  
  478.     DeleteMsgPort(RestReplyPort);
  479. }
  480.  
  481. void    DoScan(void)
  482.  
  483. /* This routine starts a scan backup procedure asynchronously. See DoBackup() for
  484.    details. */
  485.  
  486. {
  487.     struct      DiavoloAPIMsg   APIMsg, ScanMsg;
  488.     struct      MsgPort         *ScanReplyPort;
  489.  
  490.     if(! (ScanReplyPort = CreateMsgPort()))
  491.     {
  492.         printf("Error creating own message port!\n");
  493.         return;
  494.     }
  495.  
  496.     ScanMsg.DAPI_Message.mn_ReplyPort = ScanReplyPort;
  497.     ScanMsg.DAPI_Command = DAPI_STARTSCAN;
  498.     ScanMsg.DAPI_Arg1 = 2;      /* 2nd backup on tape */
  499.     ScanMsg.DAPI_Ptr1 = "Passwort";
  500.  
  501.     printf("Starting Scan\n");
  502.     PutMsg(APIPort,&ScanMsg);
  503.  
  504.     printf("Unlocking UI\n");
  505.     APIMsg.DAPI_Command = DAPI_LOCKUI;
  506.     APIMsg.DAPI_Arg1 = FALSE;
  507.     DoCommand(&APIMsg);
  508.  
  509.     WaitForCompletion(&ScanMsg);
  510.  
  511.     DeleteMsgPort(ScanReplyPort);
  512. }
  513.  
  514.  
  515. void main(void)
  516.  
  517. {
  518.     struct      DiavoloAPIMsg   APIMsg;
  519.     struct      PrefsFile       PF;
  520.  
  521.     /* First create our own message port */
  522.  
  523.     if(! (MyReplyPort = CreateMsgPort()))
  524.     {
  525.         printf("Error creating own message port!\n");
  526.         return;
  527.     }
  528.  
  529.  
  530.     /* Use forbid to secure the FindPort Operation (suggested in Exex autodocs) */
  531.  
  532.     Forbid();
  533.  
  534.  
  535.     /* Look for Diavolo message port */
  536.  
  537.     if(! (APIPort = FindPort(RENDEZVOUS_NAME)))
  538.     {
  539.         Permit();
  540.         printf("Couldn't find Diavolo API port!\n");
  541.         DeleteMsgPort(MyReplyPort);
  542.         return;
  543.     }
  544.  
  545.     Permit();
  546.  
  547.     /* Rendezvous with Diavolo */
  548.  
  549.     APIMsg.DAPI_Command = DAPI_RENDEZVOUS;
  550.     DoCommand(&APIMsg);
  551.  
  552.  
  553.     /* The following is a sequence of commands which wont work this way on your
  554.        system. Use them only as examples or to test the functions by activating only
  555.        specific parts of the code. */
  556.  
  557.  
  558.     /* First a typical backup procedure cycle */
  559.  
  560.  
  561. /* // Example1: Lock Userinterface
  562.  
  563.     printf("Locking UI\n");
  564.     APIMsg.DAPI_Command = DAPI_LOCKUI;
  565.     APIMsg.DAPI_Arg1 = TRUE;
  566.     DoCommand(&APIMsg);
  567. */
  568.  
  569.  
  570. /* // Example2: Go to backup device selection window
  571.  
  572.     printf("Going to backup window\n");
  573.     APIMsg.DAPI_Command = DAPI_INITBACKUP;
  574.     DoCommand(&APIMsg);
  575. */
  576.  
  577.  
  578. /* // Example3: Change configuration. In this case: Alter backup destination to
  579.    //           SCSI Tape device
  580.  
  581.     printf("Altering Destination\n");
  582.  
  583.  
  584.     /* First, get the current configuration */
  585.  
  586.     APIMsg.DAPI_Command = DAPI_ASKCONFIG;
  587.     APIMsg.DAPI_Ptr1 = &PF;
  588.     APIMsg.DAPI_Arg1 = sizeof(struct PrefsFile);
  589.     DoCommand(&APIMsg);
  590.  
  591.  
  592.     /* Make only neccessary changes */
  593.  
  594.     PF.prf_BackupMedium = MEDIUM_DEVICE;
  595.  
  596.  
  597.     /* Write the configuration back to Diavolo */
  598.  
  599.     APIMsg.DAPI_Command = DAPI_CHANGECONFIG;
  600.     APIMsg.DAPI_Ptr1 = &PF;
  601.     DoCommand(&APIMsg);
  602. */
  603.  
  604.  
  605. /* // Example4: Clear all previous file selections
  606.  
  607.     printf("Clearing lists\n");
  608.     APIMsg.DAPI_Command = DAPI_CLEARLISTS;
  609.     DoCommand(&APIMsg);
  610. */
  611.  
  612.  
  613. // Example5: Select files for backup without using a filter file.
  614.  
  615.     printf("Making selection\n");
  616.     APIMsg.DAPI_Command = DAPI_BACKSELECT;
  617.     APIMsg.DAPI_Ptr1 = "Private:";              /* Partition to scan */
  618.     APIMsg.DAPI_Ptr2 = "Treiber/#?";            /* Path and pattern of files to select */
  619.     APIMsg.DAPI_Ptr3 = NULL;                    /* No date selection used */
  620.     APIMsg.DAPI_Ptr4 = NULL;                    /* No scan exclusion pattern */
  621.     APIMsg.DAPI_Arg1 = DAPI_SEL_INCLUDE;        /* INCLUDE files matching to pattern */
  622.     APIMsg.DAPI_Arg2 = 0;                       /* Ignore archive flag */
  623.     APIMsg.DAPI_Arg3 = TRUE;                    /* Include subdirectories */
  624.     APIMsg.DAPI_Arg4 = FALSE;                   /* Don't ignore empty directories */
  625.     DoCommand(&APIMsg);
  626.  
  627.     APIMsg.DAPI_Command = DAPI_BACKSELECT;
  628.     APIMsg.DAPI_Ptr1 = "Private:";              /* Another selection for the same partition.
  629.                                                    As it is already scanned, Diavolo won't scan it
  630.                                                    again. */
  631.     APIMsg.DAPI_Ptr2 = "Tools/#?";              /* Another path to select files from */
  632.     APIMsg.DAPI_Ptr3 = NULL;                    /* Again no date selection */
  633.     APIMsg.DAPI_Ptr4 = NULL;                    /* No scan exclusion pattern */
  634.     APIMsg.DAPI_Arg1 = DAPI_SEL_INCLUDE;        /* INCLUDE files */
  635.     APIMsg.DAPI_Arg2 = 0;                       /* Ignore archive flags */
  636.     APIMsg.DAPI_Arg3 = TRUE;                    /* Include subdirectories */
  637.     APIMsg.DAPI_Arg4 = FALSE;                   /* Don't ignore empty directories */
  638.     DoCommand(&APIMsg);
  639.  
  640.     APIMsg.DAPI_Command = DAPI_BACKSELECT;
  641.     APIMsg.DAPI_Ptr1 = "Private:Microdot";      /* Example of the use of a specific path as a partition.
  642.                                                    Same as "Select subdir" from the device selection. Only
  643.                                                    this path will be scanned, and it will listed seperately
  644.                                                    in the volume list. */
  645.     APIMsg.DAPI_Ptr2 = "#?";                    /* Select all files */
  646.     APIMsg.DAPI_Ptr3 = NULL;                    /* No date selection */
  647.     APIMsg.DAPI_Ptr4 = NULL;                    /* No scan exclusion pattern */
  648.     APIMsg.DAPI_Arg1 = DAPI_SEL_INCLUDE;        /* INCLUDE files */
  649.     APIMsg.DAPI_Arg2 = 0;                       /* Ignore archive flags */
  650.     APIMsg.DAPI_Arg3 = TRUE;                    /* Include subdirectories */
  651.     APIMsg.DAPI_Arg4 = FALSE;                   /* Don't ignore empty directories */
  652.     DoCommand(&APIMsg);
  653.  
  654.     APIMsg.DAPI_Command = DAPI_BACKSELECT;
  655.     APIMsg.DAPI_Ptr1 = "WB_2.x";                /* Now we want to image backup this partition. */
  656.     APIMsg.DAPI_Arg1 = DAPI_SEL_IMAGE;          /* IMAGE-backup */
  657.     APIMsg.DAPI_Arg2 = TRUE;                    /* Save only used blocks */
  658.     DoCommand(&APIMsg);
  659.  
  660.     APIMsg.DAPI_Command = DAPI_BACKSELECT;
  661.     APIMsg.DAPI_Ptr1 = "Work:MovieShop/MovieShop.prj";
  662.                                                 /* The last example shows how to select a MovieShop project */
  663.     APIMsg.DAPI_Arg1 = DAPI_SEL_MOVIE;          /* IMAGE-backup */
  664.     DoCommand(&APIMsg);
  665.  
  666.  
  667.  
  668. /* // Example6: Select files for backup using a filter file.
  669.  
  670.     printf("Using selection filter\n");
  671.     APIMsg.DAPI_Command = DAPI_USEFILTER;
  672.     APIMsg.DAPI_Ptr1 = (char *)"Testfilter.filter";
  673.     DoCommand(&APIMsg);
  674.     printf("Results: Partitions: %ld, Directories: %ld, Files: %ld, Size: %ld\n",APIMsg.DAPI_Arg1,
  675.             APIMsg.DAPI_Arg2,APIMsg.DAPI_Arg3,APIMsg.DAPI_Arg4);
  676. */
  677.  
  678.  
  679. /* // Now, start backup
  680.  
  681.     DoBackup();
  682. */
  683.  
  684. /* // Do Autocompare (DoRestore() manages this, just give the correct command name)
  685.  
  686.     DoRestore(DAPI_COMPAREBACKUP);
  687. */
  688.  
  689.  
  690. /* // Return to the main menu
  691.  
  692.     APIMsg.DAPI_Command = DAPI_MAINMENU;
  693.     DoCommand(&APIMsg);
  694. */
  695.  
  696.  
  697.     /* Now, a typical compare procedure cycle */
  698.  
  699. /* // Lock the user interface
  700.  
  701.     printf("Locking UI\n");
  702.     APIMsg.DAPI_Command = DAPI_LOCKUI;
  703.     APIMsg.DAPI_Arg1 = TRUE;
  704.     DoCommand(&APIMsg);
  705. */
  706.  
  707.  
  708. /* // Go to compare device selection
  709.  
  710.     printf("Going to compare window\n");
  711.     APIMsg.DAPI_Command = DAPI_INITRESTORE;
  712.     DoCommand(&APIMsg);
  713. */
  714.  
  715.  
  716. /* // Before any selection can take place, the backup has to be scanned.
  717.  
  718.     DoScan();
  719. */
  720.  
  721.  
  722. /* // The scan procedure has unlocked the user interface (see DoScan()), so
  723.    // it must be locked again.
  724.  
  725.     printf("Locking UI\n");
  726.     APIMsg.DAPI_Command = DAPI_LOCKUI;
  727.     APIMsg.DAPI_Arg1 = TRUE;
  728.     DoCommand(&APIMsg);
  729. */
  730.  
  731.  
  732. /* // Example7: File selection for compare/restore procedure. Note that filters
  733.    // won't work here!
  734.    // Note that normally all files are already selected after the scan has been
  735.    // completed.
  736.  
  737.     APIMsg.DAPI_Command = DAPI_RESTSELECT;
  738.     APIMsg.DAPI_Ptr1 = "Private:";              /* Partition to select files from. It
  739.                                                    must be a partition, path or assign present
  740.                                                    in the backup of course */
  741.     APIMsg.DAPI_Ptr2 = "ram:";                  /* New restore/compare destination or NULL if not to change */
  742.     APIMsg.DAPI_Ptr3 = "#?";                    /* Path and pattern for selection */
  743.     APIMsg.DAPI_Ptr4 = NULL;                    /* No date selection */
  744.     APIMsg.DAPI_Arg1 = FALSE;                   /* EXCLUDE all files matching the pattern */
  745.     APIMsg.DAPI_Arg2 = 0;                       /* Ignore archive flag */
  746.     APIMsg.DAPI_Arg3 = TRUE;                    /* Include subdirectories */
  747.     APIMsg.DAPI_Arg4 = FALSE;                   /* Don't ignore empty directories */
  748.     DoCommand(&APIMsg);
  749.  
  750.     APIMsg.DAPI_Command = DAPI_RESTSELECT;
  751.     APIMsg.DAPI_Ptr1 = "Private:Microdot";      /* This is an example of a absolute path as a partition.
  752.                                                    It can only be used, if the backup contains a seperate
  753.                                                    entry for this path, i.e. this entry is listed in the
  754.                                                    volumes list. */
  755.     APIMsg.DAPI_Ptr2 = NULL;                    /* Don't change restore/compare destination */
  756.     APIMsg.DAPI_Ptr3 = "#?";                    /* Match all files */
  757.     APIMsg.DAPI_Ptr4 = NULL;                    /* No date selection */
  758.     APIMsg.DAPI_Arg1 = FALSE;                   /* EXCLUDE all files */
  759.     APIMsg.DAPI_Arg2 = 0;                       /* Ignore archive flags */
  760.     APIMsg.DAPI_Arg3 = TRUE;                    /* Include subdirectories */
  761.     APIMsg.DAPI_Arg4 = FALSE;                   /* Don't ignore empty directories */
  762.     DoCommand(&APIMsg);
  763.  
  764.     APIMsg.DAPI_Command = DAPI_RESTSELECT;
  765.     APIMsg.DAPI_Ptr1 = "Private:";              /* Select from Private: */
  766.     APIMsg.DAPI_Ptr2 = NULL;                    /* Don't change destination */
  767.     APIMsg.DAPI_Ptr3 = "#?.info";               /* Select all files matching to #?.info */
  768.     APIMsg.DAPI_Ptr4 = NULL;                    /* No date selection */
  769.     APIMsg.DAPI_Arg1 = TRUE;                    /* INCLUDE matching files */
  770.     APIMsg.DAPI_Arg2 = 0;                       /* Ignore archive flags */
  771.     APIMsg.DAPI_Arg3 = TRUE;                    /* Include subdirectories */
  772.     APIMsg.DAPI_Arg4 = TRUE;                    /* Ignore empty directories (in this case: Don't select them) */
  773.     DoCommand(&APIMsg);
  774. */
  775.  
  776.  
  777. /* // Start compare operation. Note that DAPI_STARTRESTORE starts BOTH compare and restore,
  778.    // what operation is to be started is defined by DAPI_INITCOMPARE or DAPI_INITRESTORE
  779.    // above!
  780.  
  781.     DoRestore(DAPI_STARTRESTORE);
  782. */
  783.  
  784.  
  785. /* // Example8: Create file and error reports
  786.  
  787.     APIMsg.DAPI_Command = DAPI_CREATEREPORT;
  788.     APIMsg.DAPI_Arg1 = TRUE;                    /* Create filelist */
  789.     APIMsg.DAPI_Arg2 = FALSE;                   /* Use condensed output */
  790.     APIMsg.DAPI_Ptr1 = "ram:filelist";             /* Destination name of report */
  791.     DoCommand(&APIMsg);
  792.  
  793.     APIMsg.DAPI_Command = DAPI_CREATEREPORT;
  794.     APIMsg.DAPI_Arg1 = FALSE;                   /* Create errorreport */
  795.     APIMsg.DAPI_Ptr1 = "ram:errorlist";
  796.     DoCommand(&APIMsg);
  797. */
  798.  
  799.  
  800. /* // Back to main menu
  801.  
  802.     printf("MainMenu\n");
  803.     APIMsg.DAPI_Command = DAPI_MAINMENU;
  804.     DoCommand(&APIMsg);
  805. */
  806.  
  807.  
  808. /* // Example9: Issue an SCSI command
  809.  
  810.     APIMsg.DAPI_Command = DAPI_SCSICOMMAND;
  811.     APIMsg.DAPI_Arg1 = 3;                       /* Eject tape */
  812.     DoCommand(&APIMsg);
  813. */
  814.  
  815.  
  816. /* // Quit Diavolo
  817.  
  818.     printf("Quit\n");
  819.     APIMsg.DAPI_Command = DAPI_QUIT;
  820.     DoCommand(&APIMsg);
  821. */
  822.  
  823.  
  824. /* // Close connection with client
  825.  
  826.     printf("Good bye\n");
  827.     APIMsg.DAPI_Command = DAPI_GOODBYE;
  828.     DoCommand(&APIMsg);
  829. */
  830.  
  831.  
  832.     DeleteMsgPort(MyReplyPort);
  833. }
  834.